#include "addsubtaskw.h"
#include "ui_addsubtaskw.h"

AddSubTaskW::AddSubTaskW(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddSubTaskW),
    _insertRow(0)
{
    ui->setupUi(this);
    // 设置关闭窗口后不退出程序
    setAttribute(Qt::WA_QuitOnClose, false);
    this->setWindowTitle("添加子任务");
    this->setWindowIcon(QIcon(":/pics/trayico"));
    // 禁止调整窗口大小
    setFixedSize(this->width(), this->height());
}

AddSubTaskW::AddSubTaskW(int insertRow, QWidget *parent):
    QDialog(parent),
    ui(new Ui::AddSubTaskW),
    _insertRow(insertRow)
{

    ui->setupUi(this);
    this->setWindowTitle("添加子任务");
    setAttribute(Qt::WA_DeleteOnClose,true);
//    this->setWindowIcon(QIcon(":/pics/favicon"));
    // 禁止调整窗口大小
    setFixedSize(this->width(), this->height());
}

AddSubTaskW::~AddSubTaskW()
{
    delete ui;
}

void AddSubTaskW::on_create_clicked()
{
    QString name = ui->name->text();
    if (name.isEmpty()) {
        QMessageBox::warning(this, "提示","子任务名不能为空!","确定");
        return;
    }
    int tomatoes = ui->tomatoes->text().toInt();
    QString describe = ui->textEdit->toPlainText();

    subTask subtask;
    subtask.name = name;
    subtask.tomato = tomatoes;
    subtask.achieve = 0;
    subtask.describe = describe;


    emit sendNewSubTask(_insertRow, subtask);
    this->close();
}
